package com.education.service.impl;

import java.util.List;

import com.education.model.StuMessageDo;
import com.education.model.StudentScoreModel;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.education.dao.StuIndexDao;
import com.education.model.ResultDo;
import com.education.model.StuIndexDo;
import com.education.service.IStuIndexService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;


/**
 * 学生主页
 * @author 刘帅
 *
 */
@Service
public class StuIndexServiceImpl implements IStuIndexService {

    /**
     * 学生主页接口
     */
    @Autowired
    private StuIndexDao stuIndex;
    
    /**
     * 日志记录类
     */
    private static Logger MYLOGGER = LogManager.getLogger(StuIndexServiceImpl.class);
    
    /**
     * 查询该学生的课程
     * @return 课程集合
     */
    public ResultDo<PageInfo<StuIndexDo>> queryCourse(int stuId,Integer pageNo, Integer pageSize) {
        
        pageNo = pageNo == null?1:pageNo;
        pageSize = pageSize == null?3:pageSize;
        
        //开启分页 参数为当前页和数据条数
        PageHelper.startPage(pageNo, pageSize);
        //查询该学生的课程
        List<StuIndexDo> courseList = stuIndex.queryCourse(1);
        
        //将查询结果传给PageInfo对象
        PageInfo<StuIndexDo> page = new PageInfo<StuIndexDo>(courseList);
        ResultDo<PageInfo<StuIndexDo>> resultDo = new ResultDo<PageInfo<StuIndexDo>>();
        resultDo.setResData(page);
        MYLOGGER.info(page.getPageNum());
        return resultDo;
    }

    /**
     * 学生端学生学籍信息查询  马松
     * @param stuId  学生id
     * @return
     * @throws Exception
     */
    @Override
    public List<StuMessageDo> queryStuById(Integer stuId) throws Exception {
        List<StuMessageDo> stuMsgList = stuIndex.queryStuById(stuId);
        MYLOGGER.info("学生学籍实现类："+stuMsgList);
        return stuMsgList;
    }


    /**
     * 学生端学生考试成绩  马松
     * @param studentId  学生id
     * @return  根据登录的学生ID查询当前学生
     * @throws Exception
     */
    @Override
    public List<StudentScoreModel> queryStuScoreById(Integer studentId) throws Exception {
        List<StudentScoreModel> stuScoreList =  stuIndex.queryStuScoreById(studentId);
        MYLOGGER.info("学生考试成绩："+stuScoreList);
        return stuScoreList;
    }

    /**
     *  学生端学生成绩详细信息
     */
    @Override
    public ResultDo<StudentScoreModel> qrerystuIdDetail(Integer studentId) throws Exception {
        StudentScoreModel ssm =  stuIndex.qrerystuIdDetail(studentId);
        ResultDo<StudentScoreModel> res = new ResultDo<StudentScoreModel>();
        res.setResData(ssm);
        return res;
    }



    /**
     * by 曹朋 2017.8.15
     * 根据登录学生的id查询其参加的课程
     * @param studentId 学生id
     * @return 学生课程集合
     * @throws Exception
     */
    public List<StuIndexDo> selectCurrCourse(Integer studentId) throws Exception {
        List<StuIndexDo> list=stuIndex.currCourse(studentId);
        return list;
    }

    /**
     * by 曹朋 2017.8.17
     * @param partId 观看课程的id
     * @return 修改的条数
     * @throws Exception
     */
    public int partFrequence(Integer partId) throws Exception {
        int line=stuIndex.partFrequence(partId);
        return line;
    }

}
